package com.nip.trainning.Common;

import java.io.File;

import android.os.Environment;

public class Utilities  {
	
	/**
	 * Create the folder
	 * 
	 * @param root
	 *            dir root
	 * @param folderName
	 *            folder create
	 * @return
	 */
	private static File CreateFolder(File root, String folderName) {

		if (root != null) {

			File file = new File(root, folderName);

			if (!file.exists()) {
				if (file.mkdir()) {
					return file;
				} else {
					return null;
				}
			} else {
				return file;
			}

		} else {
			return null;
		}
	}

	/**
	 * Create folder contain database
	 * 
	 * @return True - created success / False - Created error
	 */
	
	public static File CreateFolderInSdCard() {
		if (Environment.getExternalStorageState().equals(
				Environment.MEDIA_MOUNTED)) {
			File file = CreateFolder(Environment.getExternalStorageDirectory(),
					Constant.ANDROID_FOLDER);
			file = CreateFolder(file, Constant.DATA_FOLDER);
			file = CreateFolder(file, Constant.APPLICATION_FOLDER);
			file = CreateFolder(file, Constant.DATABASE_FOLDER);
			if (file == null) {
				return null;
			}
			return file;

		} else {
			return null;
		}
	}
}
